package com.roncoo.education.api;

import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import com.roncoo.education.api.request.MemberRequest;
import com.roncoo.education.db.entity.Member;
import com.roncoo.education.db.service.MemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/admin")
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class MemberAdminController {

    @Resource
    private MemberService memberService;

    @PostMapping("/getMemberPage")
    public String getMemberPage(@Valid @RequestBody MemberRequest req){
        PageInfo<Member> pageInfo = memberService.getMemberPages(req);
        return JSONUtil.toJsonStr(pageInfo);
    }

    @GetMapping("/getMember")
    public String getMemberDetail(Long id){
        Member news = memberService.getMemberById(id);
        return JSONUtil.toJsonStr(news);
    }
}
